﻿<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/news.css"></link>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><? echo $title ;?></title>
</head>

<?php
/*
*  news update
 *    A Part of snock project
 *       Author king-of-war
 *      Last modified 2009-4-6
 *
 *  designed For news update
 */
@session_start();
$root_path='../'; //set root_path of this dir

 error_reporting(E_ALL^E_NOTICE); //去除变量为空错误

include_once $root_path.'admin/class/verify.class.php';
include_once $root_path.'admin/class/news.class.php';
include_once $root_path.'admin/class/fun_common.php';
include_once $root_path.'admin/class/error.class.php';
$editor=new fun_common($root_path);
$demo=new news($root_path);
$check=new verify($root_path);
$check->identity_check(3);
$error=new Errmsg();
/*
* check the array $_GET
*/

if($_GET['id']!=''){
$id=$_GET['id'];
static $image='';
}else{
$id='2';
$info='请选择要编辑的新闻';
$error->error_chinese($info);

exit;
}

 
if(isset($_POST['upload'])){
 
      if(is_uploaded_file($_FILES['upfile']['tmp_name'])){
        $upfile=$_FILES['upfile'];
               $name=$upfile['name'];
        $type=$upfile['type'];
        $size=$upfile['size'];
        $tmp_name=$upfile['tmp_name'];

        switch($type){
            case 'image/pjpeg': $ok=1;
            break;
            case 'image/jpeg': $ok=1;
            break;
            case 'image/gif': $ok=1;
            break;
            case 'image/png': $ok=1;
            break;
            default: $ok=0;
            break;
        }
        if($ok){

move_uploaded_file($tmp_name,'../images/uploads/'.$name);
            if($upfile['error']==0){
                $dir='images/uploads/'.$name;
           $image=$dir;
            }else{
                echo
'&Eacute;&Iuml;&acute;&laquo;&Ecirc;&sect;&deg;&Uuml;';}

        }else{
            echo
'&sup2;&raquo;&Ocirc;&Ecirc;&ETH;&iacute;&acute;&Euml;&Icirc;&Auml;&frac14;&thorn;&Agrave;&agrave;&ETH;&Iacute;';}
    }

}


    if(isset($_POST['submit'])){

   $id=$_GET['id'];
   $title=$_POST['title'];
   $comments=$_POST['comments'];
   $author=$_POST['author'];
   $verify=$_POST['verify'];
   $image=$_POST['image'];
   $bool=$demo->news_add($id,$title,$image,$comments,$author,$verify,'2');

   if($bool){
     $info='新闻更新成功';
$error->error_chinese($info);
exit;

   }else{
    $info='请检查您的输入并确认他们是正确的';
$error->error_chinese($info);
exit;
   }
}


    /*
     * define  news read function
     */

$id=$_GET['id'];
    $pass=$demo->news_get($id,1);

 $max=count($pass);

$news=array();

if(is_array($pass)){
    $news['id']=$pass[0]->get_id();
    $news['title']=$pass[0]->get_title();
    $news['images']=$pass[0]->get_images();
    $news['comments']=$pass[0]->get_comments();
    $news['author']=$pass[0]->get_author();
    $news['date']=$pass[0]->get_date();
    $news['verify']=$pass[0]->get_verify();
}

if(!isset($dir)){
    $dir=$news['images'];
}
if(!isset($image)){
$dir=$image;
}
?>

<body>
<br>
<form action="news_update.php?id=<?php echo $news['id']; ?>" enctype="multipart/form-data" method="post"
	name="news_update">
<label for="title">标题：</label> <input type="text" name="title"
	id="title" value="<?php echo $news[title] ;?>"><br />
<br />
上传图片：<input name="upfile" type="file">&nbsp;&nbsp;&nbsp;&nbsp; <input
	type="submit" name="upload" value="上传"><br />
<br />
上传时请使用英文或拼音，暂不支持中文<br>
<br>
<br>
图片路径：<input type="text"  name="image" value="<?php echo $dir ;?>"><br />
<br><br>
<?php
/*
*create the editor
* $name nean names   $w mean width  $h means heidth  $toobar mean toobarset  $value mean value
*/
$name='comments';
$w="600";
$h="400";
$toobar="liujie";
$value = $news['comments'];
$editor->create_editor($name,$h,$w,$toobar,$value);

?>
 <br />
<br />
<br />
<label for="author">作者： </label>
<input type="text" name="author" value="<?php echo $news['author'] ;?>"><br />
<br />
<label for="verify">是否通过审核：
	<?php
if ($news['verify']=='1')
{?>
<input type="radio" name="verify"
	value="1"  checked="checked">是
	<input type="radio" name="verify" value="0">否
<?php }else{?>
<input type="radio" name="verify"
	value="1" >是
	<input type="radio" name="verify" value="0"  checked="checked">否
<?php }
?>
</label>

<br />
 <br>
   新闻日期： <?php echo $news['date'] ;?> <br>
<br />
<input type="submit" name="submit" value="提交"> <input
	type="reset" name="reset" value="重置"><br />
<br />
</form>
</body>
</html>



